package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.CeShi;
import com.lsy.weizhi2.mybase.BaseApp;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by 嗨哟 on 2016/12/27.
 */
public class PersonGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<String> list_num;
    private LayoutInflater inflater;
    boolean isshow;
    public PersonGridViewAdapter(Context context, List<String> list_num) {
        this.context = context;
        this.list_num = list_num;
        inflater=LayoutInflater.from(context);
    }

    public void UpData(List<String> list_num,boolean isshow){
        this.list_num = list_num;
        this.isshow=isshow;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return CeShi.person_name.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view=inflater.inflate(R.layout.person_item,viewGroup,false);
            viewHolder.person_item_iv= (ImageView) view.findViewById(R.id.person_item_iv);
            viewHolder.person_item_tv= (TextView) view.findViewById(R.id.person_item_tv);
            viewHolder.person_item_num= (TextView) view.findViewById(R.id.person_item_num);
            view.setTag(viewHolder);
            AutoUtils.autoSize(view);
        }
        viewHolder= (ViewHolder) view.getTag();
        viewHolder.person_item_iv.setImageResource(CeShi.person_images[i]);
        viewHolder.person_item_tv.setText(CeShi.person_name[i]);
        if(list_num!=null){
            if(!list_num.get(i).equals("0")){
                viewHolder.person_item_num.setVisibility(View.VISIBLE);
                viewHolder.person_item_num.setText(list_num.get(i));
            }else{
                viewHolder.person_item_num.setVisibility(View.GONE);
            }
        }else{
            viewHolder.person_item_num.setVisibility(View.GONE);
        }
        if(i==2){
            if (isshow) {
                viewHolder.person_item_num.setVisibility(View.VISIBLE);
            }
            if(BaseApp.linkedList!=null&&BaseApp.linkedList.size()!=0){
                viewHolder.person_item_num.setVisibility(View.VISIBLE);
            }
        }

        return view;
    }
    class ViewHolder{
        TextView person_item_num,person_item_tv;
        ImageView person_item_iv;
    }
}
